//==============================================================================
#ifndef _SESSIONHANDLER_H_
#define _SESSIONHANDLER_H_

#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif

#pragma once
#include "GameServer.h"
#include "..\GameClient\GameClient.h"
#include "concurrent\Runnable.h"
#include "net\ByteBuffer.h"
#include "net\ClientSocket.h"
#include "..\Message.h"
#include "..\..\Persistence\persistence\GameEvent.h"
#include <iostream>
#include <list>
#include <fstream>

using namespace concurrent;
using namespace std;
using namespace net;

class GameServer;

//==============================================================================
class SessionHandler : public Runnable
{
private:
	int sessionID;
	string clientName;
	ClientSocket* clientSocket;
	GameServer* server;
	bool _isHandling;
	bool waitSceneState;
	bool _isReady;
	CLIENT_SESSION_TYPE sessionType;

protected:
	virtual DWORD run(void);

public:
	SessionHandler(ClientSocket* clientSocket, GameServer* server);
	virtual ~SessionHandler(void);
	
	void setSessionType(CLIENT_SESSION_TYPE type);
	CLIENT_SESSION_TYPE getSessionType();
	void setIsHandling(bool flag);
	bool isHandling(void);
	void setSessionID(int sessionId);
	int getSessionID(void);
	void setClientName(string name);
	string getClientName(void);
	void setClientSocket(ClientSocket* clientSocket);
	ClientSocket* getClientSocket(void);
	void setServer(GameServer* server);
	GameServer* getServer(void);
	void setIsReady(bool flag);
	bool isReady();


	void waitForSceneStateReady();

	int startHandlingSession(void);
	void stopHandlingSession(void);
	void processMessage(Message* message);
	void sendGameFiles();
	void sendSceneState(void);

	void update(Message*);
	bool isInvalidated(void);

};

#endif
